package com.boang.controller;

import com.boang.common.Result;
import com.boang.entity.Film;
import com.boang.service.FilmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/film")
public class FilmController {

    private static final Logger log = LoggerFactory.getLogger(FilmController.class);
    @Autowired
    private FilmService filmService;


    @GetMapping("/{id}")
    public Result<Film> getFilmById(@PathVariable("id") int id) {
        Film film = filmService.selectById(id);
        return Result.success(film);
    }

    @GetMapping("/list")
    public Result<List<Film>> getFilmList() {
        List<Film> filmList = filmService.selectAll();
        return Result.success(filmList);
    }

    @PostMapping("/add")
    public Result<Film> addFilm(@RequestBody Film film) {
        int insert = filmService.insert(film);
        log.info("插入结果：{}", insert);
        return Result.success();
    }

    @PutMapping
    public Result updateFilm(@RequestBody Film film) {
        int update = filmService.update(film);
        log.info("修改结果：{}",update);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteFilm(@PathVariable int id) {
        int del = filmService.delete(id);
        log.info("删除结果：{}", del);
        return Result.success();
    }
}
